package net.sky.oa.model;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.Type;


@SuppressWarnings("unchecked")
@Entity
@Table(name = "MAIL")
public class Mail {

	  private Long id;
	  private String sender;
	  private Integer importantflag;
	  private Date sendTime;
	  private String content;
	  private String subject;
	  private String copytonames;
	  private String copytoids;
	  private String recipientnames;
	  private String recipientids;
	  private Integer  status;
	  private SysEmployee user;
	  private String fileids;
	  private String filenames;
	  private Set<MailBox> mailBoxs=new HashSet();
	  private Set<FileAttach> mailAttachs=new HashSet();
	
	@Id 
    @SequenceGenerator(name="SQ_MAIL_ID",sequenceName="SQ_MAIL_ID",allocationSize=1)
	@GeneratedValue(strategy=GenerationType.SEQUENCE,generator="SQ_MAIL_ID")
	@Column(name = "ID", unique = true, nullable = false)  
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	
	@Column(name = "SENDER")
	public String getSender() {
		return sender;
	}
	public void setSender(String sender) {
		this.sender = sender;
	}
	@Column(name = "IMPORTANTFLAG")
	public Integer getImportantflag() {
		return importantflag;
	}
	public void setImportantflag(Integer importantflag) {
		this.importantflag = importantflag;
	}
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "SENDTIME")
	public Date getSendTime() {
		return sendTime;
	}
	public void setSendTime(Date sendtime) {
		this.sendTime = sendtime;
	}
	@Lob
    @Basic(fetch = FetchType.EAGER)
    @Column(name = "CONTENT", columnDefinition = "CLOB", nullable = true)
    @Type(type ="org.springframework.orm.hibernate3.support.ClobStringType")
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
	@Column(name = "SUBJECT")
	public String getSubject() {
		return subject;
	}
	public void setSubject(String subject) {
		this.subject = subject;
	}
	@Column(name = "COPYTONAMES")
	public String getCopytonames() {
		return copytonames;
	}
	public void setCopytonames(String copytonames) {
		this.copytonames = copytonames;
	}
	@Column(name = "COPYTOIDS")
	public String getCopytoids() {
		return copytoids;
	}
	public void setCopytoids(String copytoids) {
		this.copytoids = copytoids;
	}
	@Column(name = "RECIPIENTNAMES")
	public String getRecipientnames() {
		return recipientnames;
	}
	public void setRecipientnames(String recipientnames) {
		this.recipientnames = recipientnames;
	}
	@Column(name = "RECIPIENTIDS")
	public String getRecipientids() {
		return recipientids;
	}
	public void setRecipientids(String recipientids) {
		this.recipientids = recipientids;
	}
	@Column(name = "STATUS")
	public Integer getStatus() {
		return status;
	}
	public void setStatus(Integer status) {
		this.status = status;
	}
	
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "SENDERID")
	public SysEmployee getUser() {
		return user;
	}
	public void setUser(SysEmployee user) {
		this.user = user;
	}
	@Column(name = "FILEIDS")
	public String getFileids() {
		return fileids;
	}
	public void setFileids(String fileids) {
		this.fileids = fileids;
	}
	@Column(name = "FILENAMES")
	public String getFilenames() {
		return filenames;
	}
	public void setFilenames(String filenames) {
		this.filenames = filenames;
	}
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "mail")
	public Set<MailBox> getMailBoxs() {
		return mailBoxs;
	}
	public void setMailBoxs(Set<MailBox> mailBoxs) {
		this.mailBoxs = mailBoxs;
	}
	
	@ManyToMany(fetch=FetchType.EAGER)
	@JoinTable(name="mail_attach",joinColumns={@JoinColumn(name="MAILID")},inverseJoinColumns={@JoinColumn(name="FILEID")})
    @Cascade(value={org.hibernate.annotations.CascadeType.PERSIST,org.hibernate.annotations.CascadeType.MERGE})
	public Set<FileAttach> getMailAttachs() {
		return mailAttachs;
	}
	public void setMailAttachs(Set<FileAttach> mailAttachs) {
		this.mailAttachs = mailAttachs;
	}
	
	
	
	
	  
	  
	
}
